<include file="Public:header" />
<include file="Public:left" />
<style>
    .add_img .img_case{width: 100px;height: 100px;border:1px solid #000;margin: 0 10px 10px 0;}
    .add_img .img_case img{width: 100%;height:100%;}
    .add_img .img_case:last-child .ld_close{display:none}
    .add_img{display: flex;flex-wrap:wrap;margin: 15px 0 0 125px}
    #param-items tr td{margin-top: 10px;}
</style>
<form action="{:url('Contract/add')}" method="post" enctype="multipart/form-data" id="brandForm">
    <section>
        <h2><strong>修改合同</strong></h2>
        <ul class="ulColumn2">

            <li>
                <span class="item_name" style="width:120px;">*合同名：</span>
                <input type="text" name="title" class="textbox textbox_295" value="{$data.title}">（注：必填）
            </li>
            <li>
                <span class="item_name" style="width:120px;">合同编号：</span>
                <input type="text" name="number" class="textbox textbox_295" value="{$data.number}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">开始时间：</span>
                <input type="text" class="textbox textbox_295" name="start_time" id="timea" placeholder="开始时间..." value="{$data.start_time|date='Y-m-d H:i:s',###}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">*到期时间：</span>
                <input type="text" class="textbox textbox_295" name="finish_time" id="timeb" placeholder="到期时间..." value="{$data.finish_time|date='Y-m-d H:i:s',###}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">签署人 ：</span>
                <input type="text" name="user" class="textbox textbox_295" value="{$data.user}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">签约公司：</span>
                <input type="text" name="company" class="textbox textbox_295" value="{$data.company}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">联系方式：</span>
                <input type="text" name="mobile" class="textbox textbox_295" value="{$data.mobile}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">合同照片：</span>
                
                <div class="add_img" >
                  <if condition="$data.img">
                      <volist name="data.img" id="vo" key="k">
                          <div class="img_case" style="position: relative">
                              <div class="ld_close" style="border-radius: 100px;padding:3px 5px 3px 5px;border: 1px solid red;background: red;color: #fff;position: absolute;z-index: 9999;top:-8px;right: -5px">
                                  x
                              </div>
                              <img src="__STATIC__/uploads/{$vo}" class="photoup" />
                              <input type="hidden" name="photo[]" value="{$vo}"/>
                          </div>
                      </volist>

                  </if>
                  <div class="img_case" style="position: relative">
                      <img src="__STATIC__/admin/images/add.png" class="photoup" />
                      <input type="file" name="photoname[]" class="photoname" style="display:none;" multiple/>
                  </div>
              </div>
            </li>
            <li>
                <span class="item_name" style="width:120px;">电子合同：</span>
                <input type="file" name="file" class="textbox textbox_295" id="file" value=""/>
            </li>

            <li>
                <span class="item_name" style="width:120px;">*描述：</span>
                <script id="editor" name="content" type="text" style="width:700px;height:300px;margin-left:125px; margin-top:-12px;">{$data.content}</script>
            </li>
            <input type="hidden" name="id" value="{$data.id}">
            <input type="hidden" name="file_id" value="{$data.file_id}">
            <li>
                <span class="item_name" style="width:120px;"></span>
                <input type="submit" class="link_btn" value="提交"/>
            </li>
        </ul>
    </section>
</form>
</div>
</section>
<script type="text/javascript" src="__STATIC__/laydate/laydate.js"></script>
<script>
   laydate.render({
        elem: '#timea' //指定元素
        ,type:'datetime'
    });
    laydate.render({
        elem: '#timeb' //指定元素
        ,type:'datetime'
    });
     function PreviewImage(imgFile) {

        var filextension = imgFile.value.substring(imgFile.value.lastIndexOf("."), imgFile.value.length);
        filextension = filextension.toLowerCase();
        if ((filextension != '.jpg') && (filextension != '.gif')
                && (filextension != '.jpeg') && (filextension != '.png')
                && (filextension != '.bmp')) {
            alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 !");
            imgFile.focus();
        } else {
            var path;
            path = window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
            console.log(imgFile.files[0]);
            $(imgFile).parent(".img_case").append('<div class="ld_close" style="border-radius: 100px;padding:3px 5px 3px 5px;border: 1px solid red;background: red;color: #fff;position: absolute;z-index: 9999;top:-8px;right: -5px;">x</div>');

            $(imgFile).siblings("img").attr("src",path);
            //   alert($(imgFile).parent(".img_case").html());
            $(".add_img").append('<div class="img_case"  style="position: relative"><div class="ld_close" style="border-radius: 100px;padding:3px 5px 3px 5px;border: 1px solid red;background: red;color: #fff;position: absolute;z-index: 9999;top:-8px;right: -5px">x</div> <img src="__STATIC__/admin/images/add.png" class="photoup" /><input type="file" name="photoname[]" class="photoname" style="display:none;"/></div>');
        }
    }
    $(document).on("change",'.photoname',function(){
        PreviewImage(this);
    });
    //上传图片
    $(document).on("click",'.photoup',function(){
        $(this).siblings("input").trigger("click");
    });
    //删除图片
    $(document).on("click",'.ld_close',function(){
        var obj =  $(this).parent('.img_case');
        var name = $(this).siblings("input").attr('name');
        var img = $(this).siblings("img").attr('src');
        var id = "{$data.id}"
//        alert(img)
        layer.confirm('删除数据无法恢复，并且会影响用户数据，确定删除？', {
            btn: ['确定', '取消']
        }, function() {
//        alert(name);
            if (name == 'photo[]') {
                $.post("{:url('Contract/delImg')}", {img: img,id:id}, function (result) {
                    if (result.code == '0') {
                        layer.alert(result.msg);
                    } else {
                        layer.alert(result.msg,{
                            btn: ['确定']
                        },function(index, item){
                            obj.remove();
                            layer.close(index);
                        });
                    }
                });
            } else {
                layer.alert('删除成功！',{
                    btn: ['确定']
                },function(index, item){
                    obj.remove();
                    layer.close(index);
                });
            }
        });
    });
</script>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }


</script>
</body>
</html>
